using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using QLPMT_DTO;

namespace QLPMT_DAO
{
   public class BenhDAO
    {
       DataProvider provider;
       public BenhDAO()
       {
           provider = new DataProvider();
       }
       // lay danh sach tat ca loai benh
       public List<LoaiBenh> GetAll()
       {
           provider.Connect();
           string sql = "select * from Benh";
           SqlDataReader reader = provider.ExecuteReader(sql);
           List<LoaiBenh> list = new List<LoaiBenh>();
           while (reader.Read())
           {
               string ma = reader.GetString(0);
               string ten = reader.GetString(1);
               LoaiBenh benh = new LoaiBenh(ma, ten);
               list.Add(benh);
               
           }
           provider.Disconnect();
           return list;
       }
       // Them loai benh moi vao danh sach
       public void InsertLoaiBenh(LoaiBenh dto)
       {
           provider.Connect();
           string sql = "Insert into Benh(MaLoaiBenh,LoaiBenh) values('"+dto.Maloaibenh+"','"+dto.Tenloaibenh+"')";
           provider.ExecuteQuery(sql);
           provider.Disconnect();
       }
       public void sualoaibenh(LoaiBenh dto)
       {
           provider.Connect();
           string sql = "update Benh set LoaiBenh='" + dto.Tenloaibenh + "' where MaLoaiBenh='" + dto.Maloaibenh+"'";
           provider.ExecuteQuery(sql);
           provider.Disconnect();
       }
    }
}
